<template>
  <div>
    <aplayer
      :audio="audio"
      :lrcType="0"
      music="audio[0]"
      :mini="true"
      fixed
      :autoplay="true"
    />
    <transition name="el-fade-in">
      <div class="background-img" :style="backgroundDiv" v-if="show"></div>
    </transition>
    <header-user />
    <div class="front-container">
      <!-- <div class="front-title">网站导航</div> -->
      <el-tabs v-model="activeName" type="card" @tab-click="handleClick">
        <el-tab-pane
          v-for="item in types"
          v-bind:key="item.id"
          v-bind:label="item.name"
          v-bind:name="item.name"
        >
        </el-tab-pane>

        <bookmark-view :type="selectedType"> </bookmark-view>
      </el-tabs>
    </div>
    <el-button
      class="change-img-btn"
      @click="changeWallpaper"
      circle="true"
      icon="el-icon-arrow-right"
    ></el-button>
  </div>
</template>

<script>
import { getBookMarkType } from '@/api/bookmark';
import headerUser from '@/components/header.vue';
import bookmarkView from '@/view/front/bookmarkView.vue'
import { GetUserInfo } from '@/api/user';
import { getRandomImg } from '@/api/image';
import VueParticles from 'vue-particles';

export default {
  name: 'front',
  data () {
    return {
      types: [],
      bookmarks: [],
      activeName: '',
      selectedType: '',
      userImgUrl: require("@/assets/user.png"),
      loginUser: { username: "", userid: "" },
      backgroundDiv: {
        background: "",
        backgroundRepeat: "no-repeat",
        backgroundSize: "100% 100%",

      },
      show: true,
      audio: [
        {
          name: "hometown",
          artist: "mamomo",
          url:
            "https://rl01-sycdn.kuwo.cn/e0b4f6b748705d63fb940adf17e9a169/60293e4f/resource/n2/90/40/3176438107.mp3",
          cover: 'https://img1.kuwo.cn/star/albumcover/120/45/62/128679323.jpg', // prettier-ignore
          lrc:
            "",
        },

      ],

    }
  },
  methods: {
    handleClick (tab, event) {
      this.selectedType = tab.name;
    },
    toBack () {
      this.$router.push("/management")
    },
    handleOpen (index) {
      console.log(index);
    },
    handleLogout () {
      localStorage.removeItem('authorization');
      this.$router.push("/login")
    },
    createWallpaper () {
      getRandomImg().then((response) => {
        this.backgroundDiv.background = `url(data:image/jpeg;base64,${response.data}`;
      })
    },
    changeWallpaper () {

      this.show = false;
      setTimeout(() => {
        getRandomImg().then((response) => {
          this.backgroundDiv.background = `url(data:image/jpeg;base64,${response.data}`;
          this.show = true;
        })

      }, 500)


    },



  },
  mounted () {
    getBookMarkType().then((result) => {
      this.types = result.data
    });
    let token = localStorage.getItem("authorization");
    var user = GetUserInfo(token);
    user.then((result) => {
      this.$set(this.loginUser, "username", result.data[0].username)
    });
    this.createWallpaper()

  },
  components: {
    "bookmark-view": bookmarkView,
    "header-user": headerUser,
    "vue-particles": VueParticles
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.background-img {
  width: 100vw;
  height: 100vh;
}

.front-container {
  position: absolute;
  left: 50%;
  top: 20%;
  transform: translate(-50%, -20%);
  width: 80vw;
}
.front-title {
  text-align: center;
  margin-bottom: 30px;
}

.el-header,
.el-footer {
  background-color: #b3c0d1;
  color: #333;
  text-align: center;
  line-height: 60px;
}

.el-aside {
  background-color: #d3dce6;
  color: #333;

  line-height: 200px;
  height: calc(100vh - 60px);
}

.el-main {
  background-color: #e9eef3;
  color: #333;
  text-align: center;
}

body > .el-container {
  margin-bottom: 40px;
}

.el-container:nth-child(5) .el-aside,
.el-container:nth-child(6) .el-aside {
  line-height: 260px;
}

.el-container:nth-child(7) .el-aside {
  line-height: 320px;
}
.header {
  text-align: left;
  padding-left: 20px;
  color: white;
  background-image: linear-gradient(to bottom right, #8173fd, #ffffff);
}

.header-user {
  float: right;
}
.header-user img {
  height: 40px;
  vertical-align: middle;
}

.popover-item {
  line-height: 35px;
}

.popover-item:hover {
  color: dodgerblue;
  cursor: pointer;
}

.popover-button {
  margin-right: 30px;
  margin-left: 10px;
}
.el-popover {
  min-width: 100px !important;
}
.change-img-btn {
  position: absolute;
  bottom: 20px;
  right: 20px;
}

/* 可以设置不同的进入和离开动画 */
/* 设置持续时间和动画函数 */

.slide-fade-enter, .slide-fade-leave-to
/* .slide-fade-leave-active for below version 2.1.8 */ {
  transform: translateX(10px);
  opacity: 0;
}
</style>
<style >
.el-tabs__nav {
  background-color: rgba(255, 255, 255, 0.8) !important;
}
.el-card {
  background-color: rgba(255, 255, 255, 0.8) !important;
  margin-bottom: 10px !important;
}
#source_code {
  display: inline-block;
}
</style>
